
var app = getApp();
var MyRequest = require("../../utils/MyRequest.js");
var Global = require("../../Global.js");

Page({
  data: {
    Username: '',
    Password1: '',
    Password2: '',
    Code: '',
    time: 60,
    disabled: false,
  },
  onLoad: function () {

  },
  dologin: function (event) {
    var that = this;
    that.Presenter.login(that)
  },
  Presenter: {
    changePwd: function (that) {

      //如果密码不一样

      var Data = {
        action: "resetPass2",
        mobile: that.data.Username,
        password: that.data.Password1,
        code: that.data.Code
      }
 
      MyRequest.MyGetWithToast("ChangePwd", that, function (result) {
        //用户信息存进全局
        if (result.data.success) {
           wx.navigateTo({
            url: '/pages/login/login'
          })
        }
      }, Data);
    },
    code: function (that) {
      var Data = {
        action: "findCode2",
        mobile: that.data.Username,
      }

      MyRequest.MyGetWithToast("findCode", that, function (result) {
        //开一个定时器
        that.setData({
          disabled: true
        })

        var t = setInterval(function () {
          that.setData({ time: that.data.time - 1 })
          if (that.data.time <= 0) {
            clearInterval(t);
            that.setData({
              disabled: false,
              time: 60
            })
          }
        }, 1000);


      }, Data);
    }

  },

  Username_input: function (event) {
    this.setData({ Username: event.detail.value })
  },
  Password_input1: function (event) {
    this.setData({ Password1: event.detail.value })
  },
  Password_input2: function (event) {
    this.setData({ Password2: event.detail.value })
  },
  Code_input: function (event) {
    this.setData({ Code: event.detail.value })
  },
  doSubmit: function () {
    this.Presenter.changePwd(this);
  },
  getCode: function () {

    this.Presenter.code(this);
  },
}) 